﻿using System.ComponentModel;
using Loki.Utils;

namespace Luna.Model.CRM
{
    internal class EditableCategory : Category, IEditableCategory, ICategory
    {
        #region Name

        private static PropertyChangedEventArgs argsNameChanged = ObservableHelper.CreateChangedArgs<EditableCategory>(x => x.Name);

        private static PropertyChangingEventArgs argsNameChanging = ObservableHelper.CreateChangingArgs<EditableCategory>(x => x.Name);

        public new string Name
        {
            get
            {
                return Data.Name;
            }

            set
            {
                if (value != Data.Name)
                {
                    NotifyChanging(argsNameChanging);
                    Data.Name = value;
                    NotifyChangedAndDirty(argsNameChanged);
                }
            }
        }

        #endregion Name

        #region Description

        private static PropertyChangedEventArgs argsDescriptionChanged = ObservableHelper.CreateChangedArgs<EditableCategory>(x => x.Description);

        private static PropertyChangingEventArgs argsDescriptionChanging = ObservableHelper.CreateChangingArgs<EditableCategory>(x => x.Description);

        public new string Description
        {
            get
            {
                return Data.Description;
            }

            set
            {
                if (value != Data.Description)
                {
                    NotifyChanging(argsDescriptionChanging);
                    Data.Description = value;
                    NotifyChangedAndDirty(argsDescriptionChanged);
                }
            }
        }

        #endregion Description

        #region Color

        private static PropertyChangedEventArgs argsColorChanged = ObservableHelper.CreateChangedArgs<EditableCategory>(x => x.Color);

        private static PropertyChangingEventArgs argsColorChanging = ObservableHelper.CreateChangingArgs<EditableCategory>(x => x.Color);

        public new string Color
        {
            get
            {
                return Data.Color;
            }

            set
            {
                if (value != Data.Color)
                {
                    NotifyChanging(argsColorChanging);
                    Data.Color = value;
                    NotifyChangedAndDirty(argsColorChanged);
                }
            }
        }

        #endregion Color

        public EditableCategory()
        {
            Name = "Nouvelle categorie";
            Color = "#00000000";
        }

        public EditableCategory(Category category)
            : base(category)
        {
            BeginInit();

            Name = category.Name;
            Description = category.Description;
            Color = category.Color;

            EndInit(!IsChanged);
        }
    }
}